#ifndef WIDGET_FUNCB_SMART_VISION_H
#define WIDGET_FUNCB_SMART_VISION_H

#include <QWidget>
#include <QTcpSocket>
#include <QHostAddress>
#include <QLabel>
#include "button_home_start.h"

namespace Ui {
class Widget_funcB_Smart_vision;
}

// 智能家居主界面
class Widget_funcB_Smart_vision : public QWidget {
    Q_OBJECT

public:
    explicit Widget_funcB_Smart_vision(QWidget *parent = nullptr);
    ~Widget_funcB_Smart_vision();

private slots:
    // 智能家居按钮槽函数
    void slots_button_start(bool start);
    void slots_button_send_message();
    void slots_sleep_get_up(bool start);
    void slots_air_conditioner(bool start);
    void slots_tv(bool start);
    void slots_robot(bool start);
    void slots_toaster(bool start);
    void slots_washing_machine(bool start);
    void slots_wifi(bool start);

    // TCP 相关
    void connectToServer();
    void onReadyRead();
    void onDisconnected();
    void handleReceivedCommand(const QString &msg);

private:
    Ui::Widget_funcB_Smart_vision *ui;

    // TCP 控制核心
    QTcpSocket *tcpSocket;
    QString serverIP = "127.0.0.1";
    quint16 serverPort = 12345;

    void sendMessage(const QString &msg);

    // --- 新增：设备状态（保证来回切换） ---
    bool air_on = false;
    bool tv_on = false;
    bool robot_on = false;
    bool toaster_on = false;
    bool washing_on = false;
    bool wifi_on = false;
    bool home_on = true;
    bool led_on = true;

    // 图片更新函数
    void updateDeviceIcon(QLabel *label, const QString &baseName, bool on);
    void updateSpecialIcon(QLabel *label, const QString &baseName, bool on);
    void toggleHome();
    void toggleLed();
    void initSpecialIcons();
};

#endif // WIDGET_FUNCB_SMART_VISION_H
